package com.sk.weichat.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sk.weichat.R;
import com.sk.weichat.bean.Friend;
import com.sk.weichat.bean.RoomMember;
import com.sk.weichat.db.InternationalizationHelper;
import com.sk.weichat.db.dao.FriendDao;
import com.sk.weichat.helper.AvatarHelper;
import com.sk.weichat.sortlist.BaseSortModel;
import com.sk.weichat.ui.base.CoreManager;

import java.util.List;

public class GroupMembersHeadAdapter extends BaseQuickAdapter<BaseSortModel<RoomMember>, BaseViewHolder> {

    public GroupMembersHeadAdapter(List<BaseSortModel<RoomMember>> data) {
        super(R.layout.row_sort_friend, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, BaseSortModel<RoomMember> item) {

        RoomMember member = item.getBean();
        helper.addOnClickListener(R.id.layout_row_sort);
        TextView catagory_title = helper.getView(R.id.catagory_title);
        catagory_title.setVisibility(View.GONE);
        ImageView avatarImg = helper.getView(R.id.avatar_img);
        AvatarHelper.getInstance().displayAvatar(member.getShowName(), member.getUserId(), avatarImg, true);
        TextView nick_name_tv = helper.getView(R.id.nick_name_tv);
        Friend friend = FriendDao.getInstance().getFriend(CoreManager.getSelf(mContext).getUserId(),member.getUserId());
        if (friend!=null){
            nick_name_tv.setText(TextUtils.isEmpty(friend.getRemarkName())?friend.getNickName():friend.getRemarkName());
        }else {
            nick_name_tv.setText(member.getShowName());
        }
//        nick_name_tv.setText(member.getShowName());
        TextView roles = helper.getView(R.id.roles);
        roles.setVisibility(View.VISIBLE);
        if (member.getRole() == 1) {
            roles.setBackgroundResource(R.drawable.bg_role1);
            roles.setText(InternationalizationHelper.getString("JXGroup_Owner"));
        } else if (member.getRole() == 2) {
            roles.setBackgroundResource(R.drawable.bg_role2);
            roles.setText(InternationalizationHelper.getString("JXGroup_Admin"));
        } else if (member.getRole() == 3){
            roles.setVisibility(View.GONE);
            roles.setBackgroundResource(R.drawable.bg_role3);
            roles.setText(InternationalizationHelper.getString("JXGroup_RoleNormal"));
        }else if (member.getRole()==4){
            roles.setVisibility(View.VISIBLE);
            roles.setBackgroundResource(R.drawable.bg_role4);
            roles.setText(R.string.role_invisible);
        }
    }
}
